package Element.Geom;

import java.awt.*;

import Element.*;

public class SwtGeom extends TwoNodeElemGeom implements Cloneable {

    private boolean isOpen;
    transient public AbsElem parent2;

    public SwtGeom() {
        super();
        isOpen=false;
        parent2=null;
    }

    //overloaded method
    public void initFromDB(String n, String desc, int r, int LTC,
                           boolean sn, boolean sd, int[][] si, Point pt1,
                           Point pt2,  boolean b) {
        //super==>TwoNodeElemGeom
        super.initFromDB(n, desc, r, LTC, sn, sd, si, pt1, pt2);
        isOpen = b;
    }

    public boolean getIsOpen(){ return isOpen;}
    public void    setIsOpen(boolean b){ isOpen=b;}

    public void toggle() {
        if( isOpen ) isOpen = false;
        else isOpen = true;
    }

    public boolean getIsEnergized() {
        // Open switches have no nominal voltage by algorithm design
        // although they may be energized.
        return ((!conn1.isEmpty() && ((AbsElem)conn1.elementAt(0)).
                    getResult(AbsElem.RES_NOMINAL_VOLT) != 0.0) ||
                (!conn2.isEmpty() && ((AbsElem)conn2.elementAt(0)).
                    getResult(AbsElem.RES_NOMINAL_VOLT) != 0.0));
    }

    //input : (x1,y1) and (x2,y2)
    //output: frame:Rectangle
    /*public void calcFrame(){
        double dist  = Math.sqrt( (double)((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ) );
        Point C= new Point( (x1+x2)/2, (y1+y2)/2);
        frame.width = (int) (dist/2.0);
        frame.x = C.x - frame.width;
        frame.y = C.y - frame.width;
        frame.width *=2;
        frame.height = frame.width;
    }*/

    //not a real implementation; real implementation is in the inner class of elements
    //public void draw(Graphics g){}

    public Object clone(){
        SwtGeom created = new SwtGeom();
        // all ref. in created has been instantiated such as frame, conn1,conn2, childList

        this.copyTo( created);// copy AbsElemGeom attributes to created

        //SwtGeom's own data
        created.isOpen = this.isOpen;

        return created;
    }
}